<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>集团归属配置</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="capAdvRuleInfo_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">高管角色</div>
            <div class="field" style="width: auto;">
                <div id="checkboxlist1" validate="{required:true,select:true}"></div>
            </div><span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_33">
            <div class="label">持股比例（≥）</div>
            <div class="field">
                <input name="holdRatio" id="holdRatio" type="text" class="ui-textbox" value="${splGroupCfgDtl.holdRatio }" validate="{required:true,number:true}"> %
                <span class="requiredSymbol">*</span>
            </div>
        </div>
    </div>
    <div class="btnsBox">
        <span id="saveCapAdvRuleInfo_Btn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>
</form>
<script>
    var ligerForm = null ;
    var roleTypCds = '${keyValueVOS}';
    var roleTypCd = '${splGroupCfgDtl.roleTypCd}';
    console.log("roleType =="+ JSON.stringify(roleTypCds));
    $(function () {
        ligerForm = $("#capAdvRuleInfo_form").ligerForm({
            validate: true
        });

        $("#checkboxlist1").ligerCheckBoxList({
            data: JSON.parse(roleTypCds),
            textField: 'name'
        });

        if(roleTypCd){
            console.log(roleTypCd+"---11---"+JSON.stringify(liger.get("checkboxlist1").data));
            var checkList = JSON.parse(JSON.stringify(liger.get("checkboxlist1").data)) ;
            //console.log(roleTypCd+"---22---"+JSON.stringify(checkList[0]));
            //console.log(roleTypCd+"---33---"+checkList[0].name);
            //console.log(roleTypCd+"---33---"+checkList.length);
            var roleTypCdstrs= new Array();
            roleTypCdstrs = roleTypCd.split(",");
            for(var i= 0 ;i < checkList.length; i++){
                for(var j = 0; j< roleTypCdstrs.length;j++){
                    if(checkList[i].text == roleTypCdstrs[j]){
                        checkList[i].selected = true;
                        $("#checkboxlist1-"+i)[0].checked = true;
                        break;
                    }
                }
                /*if (roleTypCd.indexOf(checkList[i].text) >= 0)
                {
                    checkList[i].selected = true;
                    $("#checkboxlist1-"+i)[0].checked = true;
                }*/
            }
        }

        /*垫款期数*/
        /* $("#isAllAdv").change(function(){
             if(this.checked){
                 liger.get("advPd").setDisabled(true);
                 //$("#advPd").attr("disabled",true);
                 ligerForm.setFieldValidate("advPd", {
                     required: false
                 });
             }else{
                 liger.get("advPd").setEnabled(true);
                 //$("#advPd").attr("disabled",false);
                 ligerForm.setFieldValidate("advPd", {
                     required: true
                 });
             }
         });*/

        /*保存*/
        $("#saveCapAdvRuleInfo_Btn").click(function (event) {
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            console.log("data =="+JSON.stringify(data));
            var checkList = liger.get("checkboxlist1").data ;
            //console.log(roleTypCd+"---22---"+JSON.stringify(checkList[0]));
            //console.log(roleTypCd+"---33---"+checkList[0].name);
            //console.log(roleTypCd+"---33---"+checkList.length);
            var roleTypCds = [];
            for(var i= 0 ;i < checkList.length; i++) {
                if ($("#checkboxlist1-"+i)[0].checked) {
                    roleTypCds.push(checkList[i].text);
                }
            }
            if(StringUtils.isEmpty(roleTypCds) && roleTypCds.length < 1){
                $.ligerDialog.SQalert({content: "集团划分高管角色未选择！", SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            data['roleTypCd'] = JSON.stringify(roleTypCds);
            $.ligerDialog.hide();
            console.log("data =="+JSON.stringify(data));
            var _url = '<%=path%>/grpcfg/splgroupcfgdtl/add.do';
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                        //frameElement.dialog.close();

                        //$("#resetBtn").click();
                        //回调刷新列表
                        //var callback=frameElement.W2W.callback;
                        //Remove_navTab();
                        //callback();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>
</body>
</html>
